package Dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import common.Dbutil;
import vo.Order;
import vo.User;

public class Orderdao {
	    private Order order;
	    private Dbutil db;
	    public Orderdao(){
	    	
	    }
	    public Orderdao(Order order){
	    	this.order = order;
	    }
		public Order getOrder() {
			return order;
		}
		public void setOrder(Order order) {
			this.order = order;
		}
		public Dbutil getDb() {
			return db;
		}
		public void setDb(Dbutil db) {
			this.db = db;
		}
	    /**
	     * 查询订单信息  
	     */
		public ArrayList<Order> do_SelectByUname(int thispage){
			ArrayList<Order> list = new ArrayList<Order>();
			db = new Dbutil();
			String sql = "select * from order1 limit "+thispage+",4 ;";
			ResultSet rs = db.executeQuery(sql);
			try {
				while(rs.next()){
				Order order = new Order();
				order.setAddress(rs.getString("address"));
				order.setNote(rs.getString("note"));
				order.setOrder_id(rs.getInt("order_id"));
				order.setOrderDate(rs.getString("orderDate"));
				order.setUser_id(rs.getInt("user_id"));
				list.add(order);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			db.closeDB();
			return list;
		}
		/**
	     * 查询订单信息  
	     */
		public ArrayList<Order> do_SelectByUname(){
			ArrayList<Order> list = new ArrayList<Order>();
			db = new Dbutil();
			String sql = "select * from order1;";
			ResultSet rs = db.executeQuery(sql);
			try {
				while(rs.next()){
				Order order = new Order();
				order.setAddress(rs.getString("address"));
				order.setNote(rs.getString("note"));
				order.setOrder_id(rs.getInt("order_id"));
				order.setOrderDate(rs.getString("orderDate"));
				order.setUser_id(rs.getInt("user_id"));
				list.add(order);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			db.closeDB();
			return list;
		}
		/**
		 * 删除商品
		 * @param 
		 * @return
		 */
		public int do_delete(String id){
			int result = -1;
			db = new Dbutil();
			String sql = "delete from order1 where order_id = "+id+";";
			result = db.executeUpdate(sql);
			db.closeDB();
			return result;
		}	

}
